<?php
/**
*	@author SignpostMarv Martin
*	@package UHU
*	@subpackage HTTP
*/

/**
*	Various helper methods for use with handling each script request
*	@package UHU
*	@subpackage HTTP
**/
class uhu_request_config
{
/**
*	@var uhu_request_config|null holds an instance of uhu_request_config 
*	@see http://uk.php.net/singleton
*/
	protected static $instance = null;
/**
*	integer the compression level to use with Gzip. Will probably be moved to {@link uhu_install_config}
*/
	const GZIP_COMPRESSION_LEVEL = 9;
/**
*	@var bool|null TRUE if the user agent supports Gzip compression, FALSE otherwise
*/
	protected $gzip = null;
/**
*	An implementation of the singleton pattern
*	@uses uhu_request_config::$gzip
*/
	protected function __construct()
	{
		$this->gzip = (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip') !== false);
	}
/**
*	An implementation of the singleton pattern
*	@uses uhu_request_config::$instance
*/
	public static function getInstance()
	{
		if(!self::$instance instanceof self)
		{
			self::$instance = new self;
		}
		return self::$instance;
	}
/**
*	@return bool TRUE if the user agent supports Gzip compression, FALSE otherwise
*	@uses uhu_request_config::$gzip
*/
	public function gzip()
	{
		return $this->gzip;
	}
/**
*	@uses uhu_HTTP_ACCEPT
*/
	public function HTTP_ACCEPT()
	{
		static $HTTP_ACCEPT = null;
		if(isset($HTTP_ACCEPT) === false && isset($_SERVER['HTTP_ACCEPT']))
		{
			$HTTP_ACCEPT = array();
			$foo = explode(',',$_SERVER['HTTP_ACCEPT']);
			if(strpos($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml') === false)
			{
				$HTTP_ACCEPT[] = new uhu_HTTP_ACCEPT('application/xhtml+xml;q=0.0');
			}
			foreach($foo as $bar)
			{
				$HTTP_ACCEPT[] = new uhu_HTTP_ACCEPT($bar);
			}
		}
		return $HTTP_ACCEPT;
	}
/**
*	Serves to get around some oddities with HTTP_IF_MODIFIED_SINCE in the $_SERVER superglobal returning an empty string
*	return string a wrapper to $_SERVER['HTTP_IF_MODIFIED_SINCE']
*/
	public function If_Modified_Since()
	{
		static $If_Modified_Since = null;
		static $set = false;
		if(isset($If_Modified_Since) === false && $set === false)
		{
			if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] !== '' && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) !== false)
			{
				$If_Modified_Since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
			}
			$set = true;
		}
		return $If_Modified_Since;
	}
}
?>